define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'message/index' + location.search,
                    add_url: 'message/add',
                    edit_url: 'message/edit',
                    // del_url: 'message/del',
                    // multi_url: 'message/multi',
                    // import_url: 'message/import',
                    table: 'message',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE',cellStyle: function () {return {css: {"max-width": "200px","overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}}},
                        // {field : 'content', title: '内容',cellStyle: function () {return {css: {"max-width": "200px","overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}}, operate: 'LIKE', align: 'left',formatter:Controller.api.formatter.content },
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'desc', title: __('Desc'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'readtime', title: __('Readtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"0":__('Type 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'order.id', title: __('Order.id')},
                        // {field: 'order.parent_id', title: __('Order.parent_id')},
                        // {field: 'order.user_id', title: __('Order.user_id')},
                        // {field: 'order.sell_id', title: __('Order.sell_id')},
                        // {field: 'order.address_id', title: __('Order.address_id')},
                        // {field: 'order.logistics_id', title: __('Order.logistics_id')},
                        // {field: 'order.coupon_id', title: __('Order.coupon_id')},
                        // {field: 'order.discount_price', title: __('Order.discount_price'), operate:'BETWEEN'},
                        // {field: 'order.order_sn', title: __('Order.order_sn'), operate: 'LIKE'},
                        // {field: 'order.pay_price', title: __('Order.pay_price'), operate:'BETWEEN'},
                        // {field: 'order.order_price', title: __('Order.order_price'), operate:'BETWEEN'},
                        // {field: 'order.freight', title: __('Order.freight'), operate:'BETWEEN'},
                        // {field: 'order.remarks', title: __('Order.remarks'), operate: 'LIKE'},
                        // {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.paytime', title: __('Order.paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.sendtime', title: __('Order.sendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.receipttime', title: __('Order.receipttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.completetime', title: __('Order.completetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.canceltime', title: __('Order.canceltime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.mode', title: __('Order.mode')},
                        // {field: 'order.status', title: __('Order.status'), formatter: Table.api.formatter.status},
                        // {field: 'order.updatetime', title: __('Order.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.deletetime', title: __('Order.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.is_show', title: __('Order.is_show')},
                        // {field: 'order.logistic_code', title: __('Order.logistic_code'), operate: 'LIKE'},
                        // {field: 'order.logistic_num', title: __('Order.logistic_num'), operate: 'LIKE'},
                        // {field: 'order.user_invoice_id', title: __('Order.user_invoice_id')},
                        // {field: 'order.type', title: __('Order.type')},
                        // {field: 'order.earnest', title: __('Order.earnest'), operate:'BETWEEN'},
                        // {field: 'order.earnesttime', title: __('Order.earnesttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.end_price', title: __('Order.end_price'), operate:'BETWEEN'},
                        // {field: 'order.end_pricetime', title: __('Order.end_pricetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'order.send', title: __('Order.send')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});